package com.wanho.java159.cb.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanho.java159.cb.mapper.MemberInformationMapper;
import com.wanho.java159.cb.po.MemberInformation;
import com.wanho.java159.cb.po.MemberInformationExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* MemberInformation 业务处理类
* @author ChaoFei.Zhang
* @date   2021-07-10
*/
@Service
@Transactional
public class MemberInformationService {
    /**MemberInformation数据访问层对象*/
    @Resource
    private MemberInformationMapper memberInformationMapper ;

    /**
    * 查询所有 MemberInformation 状态为未删除 is_deleted=0 的数据
    * @return MemberInformation所有的数据
    */
    public List<MemberInformation> list(){
        MemberInformationExample memberInformationExample = new MemberInformationExample();
        //查询 数据表中 is_deleted = 0
        memberInformationExample.createCriteria().andIsDeletedEqualTo(false) ;
        return memberInformationMapper.selectByExample(memberInformationExample) ;
    }

    /**
    * 根据删除主键删除 MemberInformation 逻辑删除 进行is_deleted=1的修改操作
    * @param id MemberInformation的主键
    * @return true 删除成功  false 删除失败
    */
    public boolean remove(Long id){
        MemberInformation memberInformation = new MemberInformation();
        memberInformation.setId(id);
        memberInformation.setIsDeleted(true);
        return memberInformationMapper.updateByPrimaryKeySelective(memberInformation) > 0 ;
    }

    /**
    * 新增一条MemberInformation记录
    * @param  memberInformation 封装新增的数据
    * @return true 新增成功  false 新增失败
    */
    public boolean save(MemberInformation memberInformation){
        memberInformation.setCreateTime(new Date());
        memberInformation.setUpdateTime(new Date());
        memberInformation.setIsDeleted(false);
        return memberInformationMapper.insert(memberInformation)>0 ;
    }

    /**
    * 根据主键查询 MemberInformation
    * @param id MemberInformation的主键
    * @return null id不存在  返回MemberInformation对象
    */
    public MemberInformation get(Long id){
        return memberInformationMapper.selectByPrimaryKey(id) ;
    }

    /**
    * 修改一条MemberInformation记录
    * @param  memberInformation 封装修改的数据
    * @return true 修改成功  false 修改失败
    */
    public boolean update(MemberInformation memberInformation) {
        memberInformation.setUpdateTime(new Date());
        return memberInformationMapper.updateByPrimaryKeySelective(memberInformation)>0 ;
    }

    /**
    * 分页查询 MemberInformation  如果有查询条件需要动态在方法体内添加条件
    * @param pageNum 页码
    * @param pageSize 分页跨度
    * @param memberInformation 封装查询的数据
    * @return 分页对象
    */
    public PageInfo<MemberInformation> listPage(Long pageNum, Long pageSize,MemberInformation memberInformation) {
        PageHelper.startPage(pageNum.intValue(),pageSize.intValue());
        MemberInformationExample memberInformationExample = new MemberInformationExample();
        MemberInformationExample.Criteria criteria = memberInformationExample.createCriteria();
        return new PageInfo<>(memberInformationMapper.selectByExample(memberInformationExample));
    }
}